package studentsystem;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class Rank {
    SQL bd = new SQL();
    Connection conn = bd.getConn();
    private int a = 1;

    Rank() {
        try {
            //数据库
            Statement stmt;
            stmt = conn.createStatement();
            String sql = "select name,num,average from students order by average desc;";
            ResultSet rs = stmt.executeQuery(sql);
            System.out.println();
            System.out.println("排名\t" + "姓名\t\t" + "学号\t\t" + "平均成绩");
            while (rs.next()) {
                System.out.println(a + "\t\t" + rs.getString("name") + "\t\t" + rs.getString("num") + "\t\t" + rs.getDouble("average"));
                a++;
            }
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new Rank();

    }

}